//寻求帮助弹出框
//时间 几天前 几分钟前
var now = new Date().getTime();
function getDateTimeStamp(dateStr){
    dateStr=dateStr.replace(/T/g,' ');
    dateStr=dateStr.replace(/\.[0-9]+/g,'');
    return Date.parse(dateStr.replace(/-/gi,"/"));
}
function getDateDiff(dateTimeStamp){
    var minute = 60000;
    var hour = 3600000;
    var day = 86400000;
    var month = 2592000000;
    var diffValue = now - dateTimeStamp;
    if(diffValue < 0){return;}
    var monthC =diffValue/month;
    var weekC =diffValue/(7*day);
    var dayC =diffValue/day;
    var hourC =diffValue/hour;
    var minC =diffValue/minute;
    if(monthC>=1){
        result="" + parseInt(monthC) + "月前";
    }
    else if(weekC>=1){
        result="" + parseInt(weekC) + "周前";
    }
    else if(dayC>=1){
        result=""+ parseInt(dayC) +"天前";
    }
    else if(hourC>=1){
        result=""+ parseInt(hourC) +"小时前";
    }
    else if(minC>=1){
        result=""+ parseInt(minC) +"分钟前";
    }else
        result="刚刚";
    return result;
}
//------------------------------------
var toparrow=document.getElementsByClassName("top-arrow")[0]; //上箭头
var findhelp=document.getElementById("findhelp"); //外部帮助按钮
var RequestAnswersDrawer=document.getElementById("outsidehelp"); //外部帮助弹出框
findhelp.onclick=function(){
    if(toparrow.style.display=="none"){
        toparrow.style.display="block";
        var timer1=setInterval(function(){
            if(parseFloat($("#outsidehelp").css("height"))>246){
                clearInterval(timer1);
            }else{
                var height=parseFloat( $("#outsidehelp").css("height"));//outsidehelp
                $("#outsidehelp").css("height",height+82);
            }
        },40)
    }else{
        //toparrow.style.display="none";
        //RequestAnswersDrawer.className="RequestAnswersDrawer transitioning_out is_asker";
        //RequestAnswersDrawer.className="RequestAnswersDrawer";
        var timer2=setInterval(function(){
            if(parseFloat($("#outsidehelp").css("height"))<=0){
                clearInterval(timer2);
                toparrow.style.display="none";
            }else{
                var height=parseFloat( $("#outsidehelp").css("height"));//outsidehelp
                $("#outsidehelp").css("height",height-82);
            }
        },40)
    }
};
//模态框淡入淡出
var overflowlist=document.getElementsByClassName("overflow"); //三个小点
var modalbg=document.getElementsByClassName("modal_bg1")[0]; //弹出框背景
var modal=document.getElementById("action_menu_container1"); //弹出框
var cancel=document.getElementsByClassName("cancel1")[0];   //弹出框中取消按钮
var timer;
for(var i=0;i<overflowlist.length;i++){
    overflowlist[i].onclick=function(){
        modalbg.style.display="block";
        modal.style.display="block";
    }
}
cancel.onclick=function(){
    if(modalbg.style.display=="block"&&modal.style.display=="block"){
        modalbg.className+=' animate_out';
        modal.className+=' animate_out';
    }
    timer=setTimeout(changeclass,100);
};
function changeclass(){
    modalbg.className='modal_bg';
    modal.className='action_menu_container';
    clearTimeout();
    timer=null;
    changedisplay();
}
function changedisplay(){
    modalbg.style.display="none";
    modal.style.display="none";
}
var sta=1;//问题状态 是否结帖 1未结帖 0结帖
var quserid="";
var currentIndex=1;
var pageSize = 10;
var qid,id;
if(location.href.match("qid")){
    var reg=/(qid=)([0-9]*)/;
    var urlfrom=location.href;
    qid=urlfrom.match(reg).splice("=")[2];
    console.log(urlfrom);
    console.log(qid);
    //var regid=/(id=)([a-zA-Z0-9]*)/;
    //id = urlfrom.match(regid).splice("=")[2];
    id=$.cookie("MYID");
}else{
    qid=$.cookie("myqid");
    id=$.cookie("MYID");
}
var imgboxheight=parseInt(document.body.clientWidth*0.3)+"px";
//点击图片展示放大图片
var winscrolltop=0;
function showbigimg(e){
    winscrolltop=$(window).scrollTop();
    //console.log(winscrolltop);
    $("#page_wrapper").css("display","none");
    $("#showimg").attr("src", e.src);
    $("#digimgplace").css("display","block");
    var bigheight=$("#digimgplace").height();
    var imgheight=$("#showimg").height();
    if(bigheight>imgheight){
        $("#showimg").css("marginTop",(bigheight-imgheight)/2);
    }
}
$("#digimgplace").click(function(){
    $("#page_wrapper").css("display","block");
    $("#digimgplace").css("display","none");
    if(winscrolltop>0){
        //console.log(winscrolltop);
        $(window).scrollTop(winscrolltop);
    }
});
var firstimg="";//用于QQ 微信分享展示 第一张图片
$().ready(function(){
    var questionUserId="";
    //获得问题
    $.ajax({
        type:"get",
        url:getquedetialurl+qid,
        datatype: "json",
        success:function(data){
            console.log(data.Data);
            var keywordarr=data.Data.keyWords.split(",");
            for(var k=0;k<keywordarr.length;k++){
                $(".TopicListItems2").append("<span>"+keywordarr[k]+"</span>");
            }
            console.log(keywordarr);
            if(data.Data.userId!=id){
                questionUserId=data.Data.userId;
            }
            if(data.Data.state===0){
                sta=0;
                document.getElementById("huidabtn").style.display="none";
                document.getElementById("findhelp").style.display="none";
                document.getElementById("friendhelp").style.display="none";
                $("#closeimg").css("display","block");
            }
            questionscore=data.Data.score;//有没有钱
            quserid=data.Data.userId;
            $("title").html(data.Data.title);
            $(".gettitle").html(data.Data.title);
            var facecode=codetoface(data.Data.content);
            $(".getcontent").html(facecode);
            $("#sharetitleword div").html(data.Data.title);
            $(".senderinfo .lf span").html(parseFloat(data.Data.score)/100);//经验有多少钱
            if(data.Data.isHideName==1){
                $(".senderinfo .rt #sendernick").append("<a>匿名</a>");
            }else{
                $(".senderinfo .rt #sendernick").append("<a href='otherpeoplepage.html?otherid="+data.Data.userId+"'>"+data.Data.userNick+"</a>");
            }
            var titletim=getDateDiff(getDateTimeStamp(data.Data.cTime));
            if(titletim&&titletim.length>0){
                $(".senderinfo .rt #sendertime").html(titletim);
            }else{
                $(".senderinfo .rt #sendertime").html("刚刚");
            }
            if(data.Data.ImgList&&data.Data.ImgList.length>0){
                firstimg="http://42.62.66.198:8003/"+data.Data.ImgList[0].imgPath;//用于QQ 微信分享展示 第一张图片
                for(var r=0;r<data.Data.ImgList.length;r++){
                    $("#qimgsplace").append("<div class='imgbox'><img src='http://42.62.66.198:8003/"+data.Data.ImgList[r].imgPath+"'/></div>");
                }
            }
            if(data.Data.score>0&&questionUserId!=id){
                $(".senderinfo .lf").css("display","block");
            }
            getanswer(qid,currentIndex,pageSize);
        }
    });

    //获得相关问题
    function relevantnews(currentIndex){
        $.ajax({
            type:"get",
            datatype:"json",
            url:relevanturl+id+"&currentIndex="+currentIndex+"&pageSize=5&questionId="+qid+"&qtype=2",
            success:function(d){
                //console.log("相关经验");
                //console.log(d);
                if(d.Data&&d.Data.length>0){
                    for(var i=0;i<d.Data.length;i++){
                        var moneyspan="";
                        if(d.Data[i].Pulu_Question.score>0){
                            moneyspan="<span class='rt' style='padding-left:16px;padding-right:20px;'>"+parseFloat(d.Data[i].Pulu_Question.score)/100+"</span>";
                        }
                        $("#Relevantq").append("<li class='Cell'><a class='tc_inner' href='questiondetail.html?qid="+d.Data[i].Pulu_Question.id+"'><span class='tc_text'>"+d.Data[i].Pulu_Question.title+"</span>"+moneyspan+"</a><div class='tc_discl'></div><div class='tc_stroke'></div></li>")
                    }
                    if(d.Data.length<5){
                        $("#morequ").css("display","none");
                    }else{
                        $("#morequ").css("display","block");
                    }
                }else{
                    $("#Relevantq").append("<li class='Cell' style='background:#E8E8E8'><a class='tc_inner' style='text-align: center'><span class='tc_text' style='font-size:15px;color:#999'>无相关问题</span></a></li>");
                    $("#morequ").css("display","none");
                }

            }
        });
    }
    relevantnews(1);//前五条相关经验
    //更多相关经验
    $("#morequ").click(function(){
        $.ajax({
            type:"get",
            datatype:"json",
            url:relevanturl+id+"&currentIndex=2&pageSize=5&questionId="+qid+"&qtype=2",
            success:function(d){
                //console.log("相关经验");
                //console.log(d);
                if(d.Data&&d.Data.length>0){
                    for(var i=0;i<d.Data.length;i++){
                        var moneyspan="";
                        if(d.Data[i].Pulu_Question.score>0){
                            moneyspan="<span class='rt' style='padding-left:16px;padding-right:20px;'>"+d.Data[i].Pulu_Question.score+"</span>";
                        }
                        $("#Relevantq").append("<li class='Cell'><a class='tc_inner' href='questiondetail.html?qid="+d.Data[i].Pulu_Question.id+"'><span class='tc_text'>"+d.Data[i].Pulu_Question.title+"</span>"+moneyspan+"</a><div class='tc_discl'></div><div class='tc_stroke'></div></li>")
                    }
                }else{
                    //$("#Relevantq").append("<li class='Cell' style='background:#ECECEC'><a class='tc_inner' style='text-align: center'><span class='tc_text' style='font-size:15px;color:#999;'>无相关问题</span></a></li>");
                    $("#morequ").css("display","none");
                }

            }
        });
        $("#morequ").css("display","none");
    });
    //弹出回答页面
    $(".answerbtn").click(function(){
        //$.cookie("qid",qid);
        $.cookie("fromquestiondetial",qid);
        location.href="answerpage.html?qid="+qid;
        //location.href="answerpage.html";
    });
    //收藏
    $("#collectit").click(function(){
        $.ajax({
            type:"post",
            datatype:"json",
            url:"http://42.62.66.198:9001/api/PuluCollection/Addpulu_collection",
            data:{"contentid":qid,"userid":id,"contenttype":2},
            success:function(data){
                console.log(data);
                $("#collectword a").html("收藏成功");
                $("#collectword").css("display","block");
                setTimeout(function(){
                    $("#collectword").css("display","none");
                },1000);
                clearTimeout();
                if(modalbg.style.display=="block"&&modal.style.display=="block"){
                    modalbg.className+=' animate_out';
                    modal.className+=' animate_out';
                }
                function disnone(){
                    document.getElementById("collectword").style.display="none";
                }
                timer=setTimeout(changeclass,100);
                setTimeout(disnone,1000);
                clearTimeout();
            }
        })
    });
    //转发 内部帮助
    var shareword=document.getElementById("shareword");
    var cancelbtn=document.getElementById("cancelbtn");
    var commentinput=document.getElementById("commentinput");
    var sendcommentbtn=document.getElementById("sendcommentbtn");
    //内部帮助 提醒谁看
    var callpersons=[];
    $("#sharebtn1").click(function(){
        $.cookie("sharequeid",qid);
        location.href="sendsharepage.html?type=2";
        //shareword.style.display="block";
        //cancelbtn.style.display="block";
        //if(modalbg.style.display=="block"&&modal.style.display=="block"){
        //    modalbg.className+=' animate_out';
        //    modal.className+=' animate_out';
        //}
        //var timer2=setInterval(function(){
        //    if(parseFloat($("#outsidehelp").css("height"))<=0){
        //        clearInterval(timer2);
        //        toparrow.style.display="none";
        //    }else{
        //        var height=parseFloat( $("#outsidehelp").css("height"));//outsidehelp
        //        $("#outsidehelp").css("height",height-82);
        //    }
        //},40);
        //function disnone(){
        //    document.getElementById("collectword").style.display="none";
        //}
        //timer=setTimeout(changeclass,100);
        //setTimeout(disnone,1000);
        //clearTimeout();
    });
    sendcommentbtn.onclick=function(){
        $("#sharewaiting").css("display","block");
        //转发
        if(commentinput.value){
            if(commentinput.value.match(/^\s+$/g)){
                $.ajax({
                    type:"post",
                    datatype:"json",
                    url:addshareurl,
                    data:{"contentid":qid,"userid":id,"fromuser":questionUserId,"des":commentinput.value,"contenttype":2},
                    success:function(data){
                        $("#sharewaiting").css("display","none");
                        console.log(data);
                        $("#collectword a").html("转发成功");
                        $("#collectword").css("display","block");
                        setTimeout(function(){
                            $("#collectword").css("display","none");
                        },1000);
                        clearTimeout();
                        shareword.style.display="none";
                    }
                })
            }else{
                $.ajax({
                    type:"post",
                    datatype:"json",
                    url:addshareurl,
                    data:{"contentid":qid,"userid":id,"fromuser":questionUserId,"des":commentinput.value,"contenttype":2},
                    success:function(data){
                        $("#sharewaiting").css("display","none");
                        console.log(data);
                        $("#collectword a").html("转发成功");
                        $("#collectword").css("display","block");
                        setTimeout(function(){
                            $("#collectword").css("display","none");
                        },1500);
                        clearTimeout();
                        shareword.style.display="none";
                    }
                })
            }

        }else{
            $.ajax({
                type:"post",
                datatype:"json",
                url:addshareurl,
                data:{"contentid":qid,"userid":id,"fromuser":questionUserId,"des":commentinput.value,"contenttype":2},
                success:function(data){
                    $("#sharewaiting").css("display","none");
                    console.log(data);
                    $("#collectword a").html("转发成功");
                    $("#collectword").css("display","block");
                    setTimeout(function(){
                        $("#collectword").css("display","none");
                    },1500);
                    clearTimeout();
                    shareword.style.display="none";
                    $("#friendhelp .rt").html("");
                    var inp = $("input.addchatpeoplebtn");
                    for(var i = 0, r = inp.length; i < r; i++){
                        inp[i].checked=false;
                    }
                }
            })
        }
        if(callpersons.length>0){
            $.ajax({
                type:"post",
                datatype:"json",
                url:insethelpurl,
                data:{"questionId":qid,"atmeuserId":id,"persons":callpersons},
                success:function(d){
                    $("#sharewaiting").css("display","none");
                    $("#page_wrapper").css("display","block");
                    shareword.style.display="none";
                    $("#friendhelp .rt").html("");
                    var inp = $("input.addchatpeoplebtn");
                    for(var i = 0, r = inp.length; i < r; i++){
                        inp[i].checked=false;
                    }
                }
            })
        }
    };
    //内部帮助选择好友完成确定按钮
    $("#choicedFDokbtn").click(function() {
        var personsname = [];
        var inp = $("input.addchatpeoplebtn");
        var inpbro = $(".friends .innerplace.tc_text");
        var tim = 0;
        for (var i = 0, r = inp.length; i < r; i++) {
            tim++;
            if (inp[i].checked) {
                console.log(inpbro[i].innerHTML);
                personsname.push(inpbro[i].innerHTML+"  ");
                callpersons.push(inp[i].dataset.fid);
            }
            if (tim === r) {
                $("#friendhelp .rt").html(personsname);
            }
        }
        $("#page_wrapper").css("display","block");
        $("#shareword").css("display","block");
        $("#choicefriend").css("display","none");
    });
    //取消
    cancelbtn.onclick=function(){
        commentinput.value="";
        shareword.style.display="none";
        cancelbtn.style.display="none";
        $("#friendhelp .rt").html("");
        var inp = $("input.addchatpeoplebtn");
        for(var i = 0, r = inp.length; i < r; i++){
            inp[i].checked=false;
        }
    }
});
//获得回答-------------------------------------------------------
var answerlength=1;// 1有回答  0没有回答了
var isover=0;//控制页面滚动 0不能滚动
function getanswer(qid,currentIndex,pageSize){
    $.ajax({
        type:"get",
        url:getanswerurl+qid+"&pageSize="+pageSize+"&currentIndex="+currentIndex+"&userId="+id,
        datatype:"json",
        success:function(data){
            //最佳回答--------------------------------------------------------------
            var db=data.Data.BestPuluanswerExt;
            if(db&&db.length>0){
                for(var l2=0;l2<db.length;l2++){
                    var answerimgs=""; //保存图片代码段
                    var htmlword="";//保存图片代码段
                    var isclick="";
                    var tim="";//保存时间
                    //判断是否有图片
                    if(db[l2].imgs.length>0){
                        for(var li=0;li<db[l2].imgs.length;li++){
                            htmlword+="<div class='imgbox' style='height:"+imgboxheight+"'><img src='http://42.62.66.198:8003/"+db[l2].imgs[li].imgPath+"' onclick='showbigimg(this)'/></div>";
                        }
                        if(htmlword){
                            answerimgs="<div class='qtext_para qimgs answerimgs'>"+htmlword+"</div>";
                        }
                    };
                    //是否已经有点赞
                    if(db[l2].userids.length>0){
                        for(var lu=0;lu<db[l2].userids.length;lu++){
                            db[l2].userids[lu].index=lu;
                            if(db[l2].userids[lu]===id){
                                isclick=" isclicked";
                            }
                        }
                    }
                    //获得时间
                    var regtime=/([0-9\-])*/;
                    //tim=db[l2].answer.ctime.match(regtime)[0];
                    tim=getDateDiff(getDateTimeStamp(db[l2].answer.ctime));
                    var sign="";
                    if(db[l2].user.sign){
                        sign=" · "+db[l2].user.sign;
                    }
                    var headerimg="<img class='profile_photo_img' src='../img/af8.png'>";
                    if(db[l2].user.userAva){
                        headerimg="<img class='profile_photo_img' src='http://42.62.66.198:8003/"+db[l2].user.userAva+"'>";
                    }

                    var newcontent=codetoface(db[l2].answer.content);
                    if(tim){
                        $("#bestanswer").append("<div class='othersanswer'> <div class='AnswerPagedList PagedList'> <div class='Answer on_question_page'> <div class='answer_text'> <div class='ContentHeader'> <div class='photo_info_layout size_small'> <div class='photo_wrapper'> <div class='photo'><a href='otherpeoplepage.html?otherid="+db[l2].user.userId+"'>"+headerimg+"</a></div> </div> <div class='info_wrapper'> <span class='feed_item_answer_user'> <span class='user'>"+db[l2].user.nick+"</span><span class='sign'>"+sign+"</span> </span> <div class='ContentFooter'>"+tim+"</div> </div> </div> </div> <div class='answer_content'> <span class='rendered_qtext'> <p class='qtext_para'>"+newcontent+"</p> "+answerimgs+"</span> </div> </div>  <div class='ActionBar'> <div class='action_bar_inner'> <div class='primary_item'> <a class='Upvote Button"+isclick+"' onclick='addgoodftn(this)' id='"+db[l2].answer.id+"'> <span>赞同</span> <span class='count seeallupvoters'>"+db[l2].upcount+"</span> </a> </div> <div class='action_item'></div> <div class='action_item'></div> </div> </div> </div> </div> </div>");
                    }else{
                        $("#bestanswer").append("<div class='othersanswer'> <div class='AnswerPagedList PagedList'> <div class='Answer on_question_page'> <div class='answer_text'> <div class='ContentHeader'> <div class='photo_info_layout size_small'> <div class='photo_wrapper'> <div class='photo'><a href='otherpeoplepage.html?otherid="+db[l2].user.userId+"'>"+headerimg+"</a></div> </div> <div class='info_wrapper'> <span class='feed_item_answer_user'> <span class='user'>"+db[l2].user.nick+"</span><span class='sign'>"+sign+"</span> </span> <div class='ContentFooter'>刚刚</div> </div> </div> </div> <div class='answer_content'> <span class='rendered_qtext'> <p class='qtext_para'>"+newcontent+"</p> "+answerimgs+"</span> </div> </div>  <div class='ActionBar'> <div class='action_bar_inner'> <div class='primary_item'> <a class='Upvote Button"+isclick+"' onclick='addgoodftn(this)' id='"+db[l2].answer.id+"'> <span>赞同</span> <span class='count seeallupvoters'>"+db[l2].upcount+"</span> </a> </div> <div class='action_item'></div> <div class='action_item'></div> </div> </div> </div> </div> </div>");
                    }
                }
                htmlword="";
                answerimgs="";
                isclick="";
                //tim="";
                $("#bestanswer").css("display","block");
            }
            //所有回答---------------------------------------------------------------
            var dd=data.Data.PuluanswerExt;
            if(dd&&dd.length>0&&dd.length===pageSize){
                answerlength=1;
                $("#addmoreanswerbtn").css("display","block");
            }else{
                answerlength=0;
                $("#addmoreanswerbtn").css("display","none");
            }
            if((dd&&dd.length==0)||!dd){
                $("#QuestionMain").css("display","none");
            }
            if(dd&&dd.length>0){
                $("#QuestionMain").css("display","block");
                for(var l=0;l<dd.length;l++){
                    var answerimgs=""; //保存图片代码段
                    var htmlword="";//保存图片代码段
                    var isclick="";
                    var tim="";//保存时间
                    //判断是否有图片
                    if(dd[l].imgs.length>0){
                        for(var li=0;li<dd[l].imgs.length;li++){
                            htmlword+="<div class='imgbox' style='height:"+imgboxheight+"'><img src='http://42.62.66.198:8003/"+dd[l].imgs[li].imgPath+"' onclick='showbigimg(this)'/></div>";
                        }
                        if(htmlword){
                            answerimgs="<div class='qtext_para qimgs answerimgs'>"+htmlword+"</div>";
                        }
                    };
                    //是否已经有点赞
                    if(dd[l].userids.length>0){
                        for(var lu=0;lu<dd[l].userids.length;lu++){
                            dd[l].userids[lu].index=lu;
                            if(dd[l].userids[lu]===id){
                                isclick=" isclicked";
                            }
                        }
                    }
                    //获得时间
                    var regtime=/([0-9\-])*/;
                    //tim=dd[l].answer.ctime.match(regtime)[0];
                    if(dd[l].answer.ctime){
                        tim=getDateDiff(getDateTimeStamp(dd[l].answer.ctime));
                    };
                    var sign="";
                    if(dd[l].user.sign){
                        sign=" · "+dd[l].user.sign;
                    }
                    //是否是发布者 是否结帖了======================================================
                    var gooverit="";
                    var pinglun="";
                    if(quserid===id&&sta===1&&dd[l].user.userId!=id){
                        gooverit="<div class='primary_item'><a class='Upvote Button gooveritbtn'><span>选为答案</span></a></div>"
                    }
                    if(sta===1){
                        pinglun="<a class='commentbtn' id='c"+dd[l].answer.id+"'>评论</a>";
                    }
                    //function reload(){
                    var tim=getDateDiff(getDateTimeStamp(dd[l].answer.ctime));
                    var headerimg="<img class='profile_photo_img' src='../img/af8.png'> ";
                    if(dd[l].user.userAva){
                        headerimg="<img class='profile_photo_img' src='http://42.62.66.198:8003/"+dd[l].user.userAva+"'> ";
                    }
                    var newcontent=codetoface(dd[l].answer.content);
                    if(tim){
                        $("#QuestionMain").append("<div class='othersanswer'> <div class='AnswerPagedList PagedList'> <div class='Answer on_question_page'> <div class='answer_text'> <div class='ContentHeader'> <div class='photo_info_layout size_small'> <div class='photo_wrapper'> <div class='photo'><a href='otherpeoplepage.html?otherid="+dd[l].user.userId+"'>"+headerimg+"</a></div> </div> <div class='info_wrapper'> <span class='feed_item_answer_user'> <span class='user'>"+dd[l].user.nick+"</span><span class='sign'>"+sign+"</span> </span> <div class='ContentFooter'>"+tim+"</div> </div> </div> </div> <div class='answer_content'> <span class='rendered_qtext'> <p class='qtext_para'>"+newcontent+"</p> "+answerimgs+"</span> </div> </div>  <div class='ActionBar'> <div class='action_bar_inner'> <div class='primary_item'> <a class='Upvote Button"+isclick+"' onclick='addgoodftn(this)' id='"+dd[l].answer.id+"'> <span>赞同</span> <span class='count seeallupvoters'>"+dd[l].upcount+"</span> </a> </div>"+gooverit+" <div class='action_item'>"+pinglun+"</div> <div class='action_item'></div> </div> </div> </div> </div> </div>");
                    }else{
                        $("#QuestionMain").append("<div class='othersanswer'> <div class='AnswerPagedList PagedList'> <div class='Answer on_question_page'> <div class='answer_text'> <div class='ContentHeader'> <div class='photo_info_layout size_small'> <div class='photo_wrapper'> <div class='photo'><a href='otherpeoplepage.html?otherid="+dd[l].user.userId+"'>"+headerimg+"</a></div> </div> <div class='info_wrapper'> <span class='feed_item_answer_user'> <span class='user'>"+dd[l].user.nick+"</span><span class='sign'>"+sign+"</span> </span> <div class='ContentFooter'>刚刚</div> </div> </div> </div> <div class='answer_content'> <span class='rendered_qtext'> <p class='qtext_para'>"+newcontent+"</p> "+answerimgs+"</span> </div> </div>  <div class='ActionBar'> <div class='action_bar_inner'> <div class='primary_item'> <a class='Upvote Button"+isclick+"' onclick='addgoodftn(this)' id='"+dd[l].answer.id+"'> <span>赞同</span> <span class='count seeallupvoters'>"+dd[l].upcount+"</span> </a> </div>"+gooverit+" <div class='action_item'>"+pinglun+"</div> <div class='action_item'></div> </div> </div> </div> </div> </div>");
                    }
                }
                htmlword="";
                answerimgs="";
                isclick="";
                //tim="";
            }
            //addgood();
            //未结帖可评论
            if(sta===1){
                comment();
            }
            seeuper(dd);
            isover=1;//控制页面滚动
        }
    });
};
//结帖按钮-------------------------------------------------------
var gofinishcurrentIndex=1;
var questionscore=0;
var havemoney=0;//问题又没有钱 0没有 1有
var waheight=window.screen.availHeight;
function getallanswer(qid,gofinishcurrentIndex){
    var clicknum=0;//点击次数 选择的人的个数
    $.ajax({
        type:"get",
        datatype:"json",
        url:getanswerurl+(qid)+"&currentIndex="+gofinishcurrentIndex+"&pageSize=15&userId="+id,
        success:function(d){
            //如果有分数
            if(questionscore>0){
                havemoney=1;
                var num=0;
                for(var i=0;i< d.Data.PuluanswerExt.length;i++){
                    //<input type='number' maxlength='3' class='inputkey' value='100' min='1' max='100'></div> %</a> <a class='mweb_action_button'><span class='cancel'>取消</span><span class=' sendword' data-id='"+d.Data.PuluanswerExt[i].answer.id+"'>确定</span></a></div> </div> </div>"
                    var headerimg="<img  src='../img/af8.png'/>";
                    if(d.Data.PuluanswerExt[i].user.userAva){
                        headerimg="<img  src='"+imgurl+d.Data.PuluanswerExt[i].user.userAva+"'/>";
                    }
                    var newcontent=codetoface(d.Data.PuluanswerExt[i].answer.content);
                    $("#newsplace").append("<div class='ts_cells'> <div class='Cell'> <div class='tc_image'>"+headerimg+"</div> <div class='tc_inner newsplaceright'> <div class='tc_text title'>"+d.Data.PuluanswerExt[i].user.nick+"</div> <div class='tc_text words'>"+newcontent+"</div> <div class='choiceimg' data-speaker='"+d.Data.PuluanswerExt[i].user.userId+"'> <img src='img/hook-no.png' class='imgno' style='display: block;'/> <img src='img/hook01.png' class='imgyes' data-id='"+d.Data.PuluanswerExt[i].answer.id+"' style='display: none'/> </div> </div> </div> </div><div class='inputbox action_menu_container' style='display:none;position:fixed;overflow:hidden;'> <div class='inner'> <div class='action_menu' style='margin-top: 100px;'> <a class='mweb_action_button cancelmoney'>请输入分配比例%</a><a class='mweb_action_button deletekey'><div class='wordinputbox'> <input type='number' maxlength='3' class='inputkey' value='100' min='1' max='100'></div> %</a> <a class='mweb_action_button'><span class='cancel cancelmoney' data-num='"+num+"'>取消</span><span class=' sendword' data-id='"+d.Data.PuluanswerExt[i].answer.id+"'>确定</span></a></div> </div> </div>");
                    num++;
                }
                var clickbtn=document.getElementsByClassName("choiceimg");//选择按钮
                var imgno=document.getElementsByClassName("imgno");//no图标
                var imgyes=document.getElementsByClassName("imgyes");//yes图标
                var inputbox=document.getElementsByClassName("inputbox");//弹出输入框
                var sendword=document.getElementsByClassName("sendword");//弹出输入框确定按钮
                var cancel=document.getElementsByClassName("cancelmoney");//弹出输入框取消按钮
                var inputkey=document.getElementsByClassName("inputkey");//弹出输入框input
                for(var r=0;r<clickbtn.length;r++){
                    clickbtn[r].index=r;
                    clickbtn[r].onclick=function(){
                        if(clickbtn[this.index].dataset.speaker===id){
                            alert("请勿选择自己");
                        }
                        else{
                            if(imgno[this.index].style.display==="block"&&clicknum<3){
                                clicknum++;
                                var me=this.index;
                                imgyes[this.index].style.display="block";
                                imgno[this.index].style.display="none";
                                inputbox[this.index].style.display="block";
                                var last=0;//输入多少钱
                                sendword[me].onclick=function(){
                                    //console.log("dianji");
                                    imgyes[me].setAttribute( 'data-score' ,inputkey[me].value) ;
                                    //allscore[d.Data[me].answer.id]=parseFloat(inputkey[me].value)/100;
                                    inputbox[me].style.display="none";
                                    var choiceimg=document.getElementsByClassName("imgyes");
                                    var tim=0;
                                    for(var r= 0,len=choiceimg.length;r<len;r++){
                                        tim++;
                                        if(choiceimg[r].dataset.score){
                                            last+=parseFloat(choiceimg[r].dataset.score);
                                        };
                                        if(tim==len){
                                            var lastinput=document.getElementsByClassName("inputkey");//弹出输入框input
                                            for(var l= 0,len2=lastinput.length;l<len2;l++){
                                                console.log("修改value");
                                                lastinput[l].value=100-last;
                                            }
                                        }
                                    }
                                };
                                //console.log("clicknum"+clicknum);
                            }
                            else if(imgno[this.index].style.display==="none"){
                                clicknum--;
                                imgyes[this.index].style.display="none";
                                imgyes[this.index].dataset.score="";
                                imgno[this.index].style.display="block";
                                //console.log("clicknum"+clicknum);
                                var last=0;//输入多少钱
                                var choiceimg=document.getElementsByClassName("imgyes");
                                var tim=0;
                                for(var r= 0,len=choiceimg.length;r<len;r++){
                                    tim++;
                                    if(choiceimg[r].dataset.score){
                                        last+=parseFloat(choiceimg[r].dataset.score);
                                    };
                                    if(tim==len){
                                        var lastinput=document.getElementsByClassName("inputkey");//弹出输入框input
                                        for(var l= 0,len2=lastinput.length;l<len2;l++){
                                            console.log("取消操作后value");
                                            lastinput[l].value=100-last;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //弹出输入框取消按钮
                for(var r2=0;r2<cancel.length;r2++){
                    cancel[r2].index=r2;
                    cancel[r2].onclick=function(e){
                        clicknum--;
                        var num= e.target.dataset.num;
                        imgyes[num].style.display="none";
                        imgno[num].style.display="block";
                        inputbox[num].style.display="none";
                    };
                }
            }else{  /////////////////////////////////////////////////////////////////////没有分数
                for(var i=0;i< d.Data.PuluanswerExt.length;i++){
                    var headerimg="<img  src='../img/af8.png'/>";
                    if(d.Data.PuluanswerExt[i].user.userAva){
                        headerimg="<img  src='"+imgurl+d.Data.PuluanswerExt[i].user.userAva+"'/>";
                    }
                    var newcontent=codetoface(d.Data.PuluanswerExt[i].answer.content);
                    $("#newsplace").append("<div class='ts_cells'> <div class='Cell'> <div class='tc_image'>"+headerimg+"</div> <div class='tc_inner newsplaceright'> <div class='tc_text title'>"+d.Data.PuluanswerExt[i].user.nick+"</div> <div class='tc_text words'>"+newcontent+"</div> <div class='choiceimg' data-speaker='"+d.Data.PuluanswerExt[i].user.userId+"'> <img src='img/hook-no.png' class='imgno' style='display: block;'/> <img src='img/hook01.png' class='imgyes' data-id='"+d.Data.PuluanswerExt[i].answer.id+"' style='display: none'/> </div> </div> </div> </div></div> </div>");
                }
                var clickbtn=document.getElementsByClassName("choiceimg");//选择按钮
                var imgno=document.getElementsByClassName("imgno");//红图标
                var imgyes=document.getElementsByClassName("imgyes");//绿图标
                for(var r=0;r<clickbtn.length;r++){
                    clickbtn[r].index=r;
                    clickbtn[r].onclick=function(){
                        if(clickbtn[this.index].dataset.speaker===id){
                            alert("请勿选择自己");
                        }
                        else{
                            if(imgno[this.index].style.display==="block"&&clicknum<3){
                                clicknum++;
                                var me=this.index;
                                imgyes[this.index].style.display="block";
                                imgno[this.index].style.display="none";
                                //console.log("clicknum"+clicknum);
                            }else if(imgno[this.index].style.display==="none"){
                                clicknum--;
                                imgyes[this.index].style.display="none";
                                imgno[this.index].style.display="block";
                                //console.log("clicknum"+clicknum);
                            }
                        }
                    }
                }
            }
        }
    })
}
$("#page_wrapper").delegate(".gooveritbtn","click",function(){
    $("#page_wrapper").css("display","none");
    $("#choicepeople").css("display","block");
    $("#newsplace div").remove();
    getallanswer(qid,1);
});
$("#closethispagebtn").click(function(){
    $("#page_wrapper").css("display","block");
    $("#choicepeople").css("display","none");
});
//结帖完成 页面返回
$("#peoplefinish").click(function(){
    console.log("点击完成按钮了");
    var answerData = [];
    var allmoney=0;
    var imgyes=document.getElementsByClassName("imgyes");//绿图标
    if(imgyes){
        if(havemoney===0){
            for(var i=0;i<imgyes.length;i++){
                if(imgyes[i].style.display==="block"){
                    var obj = {};
                    obj.answerId =imgyes[i].dataset.id;
                    obj.scorerate =0;
                    answerData.push(obj);
                    allmoney+=parseFloat(imgyes[i].dataset.score);
                }
            }
            $.ajax({
                type:"post",
                datatype:"json",
                url:overquestionurl,
                data:{ "answerData": answerData, "questionId": qid },
                success:function(d){
                    //console.log(d);
                    //havemoney=0;
                    //document.getElementById("choicepeople").style.display="none";
                    //document.getElementById("page_wrapper").style.display="block";
                    location.reload();
                    //var t=parseFloat($.cookie("fqscrollTop"));
                    //console.log(t);
                    //$("#questionlist").scrollTop(t);
                }
            })
        }else if(havemoney===1){
            for(var i=0;i<imgyes.length;i++){
                if(imgyes[i].style.display==="block"){
                    var obj = {};
                    obj.answerId =imgyes[i].dataset.id;
                    obj.scorerate =parseFloat(imgyes[i].dataset.score)/100;
                    answerData.push(obj);
                    allmoney+=parseFloat(imgyes[i].dataset.score);
                }
            }
            if(allmoney!=100){
                //金钱提示
                $("#moneynews").css("display","block");
                setTimeout(function(){
                    $("#moneynews").css("display","none");
                },2000);
                clearTimeout();
            }else{
                $.ajax({
                    type:"post",
                    datatype:"json",
                    url:overquestionurl,
                    data:{ "answerData": answerData, "questionId": qid },
                    success:function(d){
                        console.log(d);
                        //havemoney=0;
                        //document.getElementById("choicepeople").style.display="none";
                        //document.getElementById("page_wrapper").style.display="block";
                        location.reload();
                        //var t=parseFloat($.cookie("fqscrollTop"));
                        //console.log(t);
                        //$("#questionlist").scrollTop(t);
                    }
                })
            }
        }
    }
});

//点击加载更多回答-----------------------------------------------
$("#addmoreanswerbtn").click(function(){
    console.log("answerlength:"+answerlength);
    if(answerlength===1){
        currentIndex++;
        getanswer(qid,currentIndex,pageSize);
    }

});
//点赞操作
function addgoodftn(e){
    if(e.className==="Upvote Button"){
        e.className="Upvote Button isclicked";
        var countnum=$(e).children(".count").html();
        $(e).children(".count").html(parseInt(countnum)+1);
        console.log("countnum",countnum);
        $.ajax({
            type:"post",
            datatype:"json",
            url:"http://42.62.66.198:9001/api/PuluAnswerUpdown/AddAnswerUpdown",
            data:{"id":"","userId":id,"answerId":e.id,"ctime":"","etime":""},
            success:function(data){
                console.log(data);
            }
        })
    }
}
function addgood(){
    var goodbtn=document.querySelectorAll(".Upvote.Button");
    var gooodcount=document.getElementsByClassName("count");
    for(var g=0;g<goodbtn.length;g++){
        goodbtn[g].index=g;
        goodbtn[g].onclick=function(){
            //console.log(goodbtn[this.index].id);//当前ID
            //console.log(goodbtn[this.index].className);//当前class
            if(goodbtn[this.index].className==="Upvote Button"){
                goodbtn[this.index].className="Upvote Button isclicked";
                console.log(this.index);
                gooodcount[this.index].innerHTML=parseFloat(gooodcount[this.index].innerHTML)+1;
                $.ajax({
                    type:"post",
                    datatype:"json",
                    url:"http://42.62.66.198:9001/api/PuluAnswerUpdown/AddAnswerUpdown",
                    data:{"id":"","userId":id,"answerId":goodbtn[this.index].id,"ctime":"","etime":""},
                    success:function(data){
                        console.log(data);
                    }
                })
            }
        }
    }
}
//查看所有品论页面
function comment(){
    var commentbtn=document.querySelectorAll(".commentbtn");
    for(var g=0;g<commentbtn.length;g++){
        commentbtn[g].index=g;
        commentbtn[g].onclick=function(){
            location.href="comment.html?aid="+commentbtn[this.index].id;
        }
    }
}
//查看所有点赞者
//页面切换
document.getElementById("upvotersbtn").onclick=function(){
    $("#upvoters .ts_cells li.Cell").remove();
    document.getElementById("upvoters").style.display="none";
    document.getElementById("page_wrapper").style.display="block";
};
function seeuper(dd){
    var saub=document.getElementsByClassName("seeallupvoters");
    var saubid=[];
    for(var i=0;i<saub.length;i++){
        saub[i].index=i;
        saub[i].onclick=function(){
            if(dd[this.index].userids.length>0){
                saubid=dd[this.index].userids;
                document.getElementById("upvoters").style.display="block";
                document.getElementById("page_wrapper").style.display="none";
                $.ajax({
                    type:"post",
                    dataType: "json",
                    url:seealluperurl,
                    data:{"persons":dd[this.index].userids},
                    success:function(data){
                        //console.log(data);
                        if(data.Data&&data.Data.length>0){
                            for(var r=0;r<data.Data.length;r++){
                                var job="";
                                var edu="";
                                var cit="";
                                var thisid="";
                                if(data.Data[r].jobs&&data.Data[r].jobs.length>0){
                                    job=" · "+data.Data[r].jobs[0].typename;
                                }
                                if(data.Data[r].education){
                                    edu=" · "+data.Data[r].education;
                                }
                                if(data.Data[r].city){
                                    cit=" · "+data.Data[r].city;
                                }
                                if(id===data.Data[r].userId){
                                    thisid="";
                                }else if(id!==data.Data[r].userId){
                                    thisid=" href='otherpeoplepage.html?otherid="+data.Data[r].userId+"'";
                                }
                                var headerimg="<img class='profile_photo_img' src='../img/af8.png'/>";
                                if(data.Data[r].userAva){
                                    headerimg="<img class='profile_photo_img' src='http://42.62.66.198:8003/"+data.Data[r].userAva+"'/>";
                                }
                                $("#upvoters .Section .ts_cells").append("<li class='Cell has_image'><div class='tc_image'>"+headerimg+"</div><a class='tc_inner sticky_highlight'"+thisid+" href='otherpeoplepage.html?otherid="+data.Data[r].userId+"'><span class='tc_text'><span class='user'>"+data.Data[r].nick+"</span></span><div class='AnswerActorCredibilityInfo'><span>"+cit+"</span><span>"+job+"</span><span>"+edu+"</span></div></a><div class='tc_discl'></div><div class='tc_stroke'></div></li>")
                            }
                        }
                    }
                });

            }
        }
    }
}

//加载好友列表---------------------------------------------------
$.ajax({
    datatype:"json",
    type:"get",
    url:friendlisturl+id,
    success:function(d){
        if(d.Data.length>0){
            //排序
            friendarr= d.Data;
            function compare(property){
                return function(a,b){
                    var value1 = pinyin.getCamelChars(a[property]);
                    var value2 = pinyin.getCamelChars(b[property]);
                    return value1.localeCompare(value2);
                }
            }
            friendarr.sort(compare("friendnick"));
            hasharr={};//判断字母是否存在
            for(var i=0;i<friendarr.length;i++){
                friendarr[this.index]=i;
                //如果昵称开头为汉字或英文字母
                var key=pinyin.getCamelChars(friendarr[i].friendnick[0]);

                if(key.match(/[a-z|A-Z]/)){
                    if(!hasharr[pinyin.getCamelChars(friendarr[i].friendnick[0])]){
                        hasharr[pinyin.getCamelChars(friendarr[i].friendnick[0])]=i;
                    }
                    $("#a").append("<div class='section_header section_header_gray "+key+"' data-num='"+i+"' style='display:none'> <span class='"+key+"'>"+key+"</span> </div><div class='friends' id='"+friendarr[i].friendId+"'> <input type='checkbox'  class='addchatpeoplebtn' data-fid='"+friendarr[i].friendId+"'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].friendId+"'><img src='http://42.62.66.198:8003/"+friendarr[i].headimg+"' class='topic_photo_img'/> </a> </div> <div class='innerplace tc_text'>"+friendarr[i].friendnick+"</div> </div>");
                }else{
                    $("#jinghao").css("display","block");
                    $("#jinghao").append("<div class='friends' id='"+friendarr[i].friendId+"'> <input type='checkbox'  class='addchatpeoplebtn' data-fid='"+friendarr[i].friendId+"'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].friendId+"'><img src='http://42.62.66.198:8003/"+friendarr[i].headimg+"' class='topic_photo_img'/> </a> </div> <div class='innerplace tc_text'>"+friendarr[i].friendnick+"</div> </div>");
                };
            }
            //console.log(hasharr);
            for(var key in hasharr){
                $("#choicefriend .section_header.section_header_gray."+key).eq(0).css("display","block");
            };
        }
    }
});
//好友列表页 展开隐藏--------------------------------------------
$("#friendhelp").click(function(){
    $("#shareword").css("display","none");
    $("#page_wrapper").css("display","none");
    $("#choicefriend").css("display","block");
});
$("#firendgobackbtn").click(function(){
    $("#page_wrapper").css("display","block");
    $("#shareword").css("display","block");
    $("#choicefriend").css("display","none");
});
$(window).scroll(function(){
    var mainheight=$(".home_feed").height();
    //console.log("加载区域高度："+mainheight);
    var windowheight=$(window).height();
    //console.log("窗口高度："+windowheight);
    var what=$(".home_feed").offset().top;
    var chajuli=$(".home_feed").offset().top - $(window).scrollTop();
    var cz=windowheight-mainheight+50;
    if(chajuli<cz&&isover===1){
        isover=0;
        if(document.getElementById("choicepeople").style.display==="block"){
            gofinishcurrentIndex++;
            getallanswer(qid,gofinishcurrentIndex);
            console.log("页面滚动了")
        }
    }
});
//键盘事件 搜索-------------------------------------------------------
//document.onkeydown=function(event){
//    var e = event || window.event || arguments.callee.caller.arguments[0];
//    if(e && e.keyCode==13){ // enter 键
//        var word=document.getElementById("searchinput").value;
//        if(word){
//            if(word.match(/^\s+$/g)){
//                console.log("没有填信息")
//            }else{
//                location.href="search.html?searchKey="+word;
//            }
//        }
//    }
//};
$("#searchinput").click(function(){
    location.href="search.html?searchKey=";
});
$("#searchinputdiv").click(function(){
    location.href="search.html?searchKey=";
});